package main

import (
	//"database/sql"
	"github.com/astaxie/beego/orm"
	_ "github.com/go-sql-driver/mysql"
	"fmt"
)

type Users struct {
	Id int	//id
	Name string `orm:"size(100)"`	//名称
	Age int	//年龄
	Sex byte	//性别
	Country string	//国家
}


func init()  {
	//注册驱动
	orm.RegisterDriver("mysql", orm.DRMySQL)
	//设置默认数据库
	orm.RegisterDataBase("default", "mysql", "root:zqd6382639@/test?charset=utf8", 30)
	//注册定义的model
	orm.RegisterModel(new(Users))

	//创建table
	orm.RunSyncdb("default", false, true)
}

func main()  {
	o:= orm.NewOrm()

	//user := Users{Name:"slene"}

	//插入表
	//id, err := o.Insert(&user)
	//fmt.Println("id=",id," err:",err)

	//更新表
	user := Users{Id: 1}
	err := o.Read(&user)
	fmt.Println(err, user.Name)
	user.Name = "qidong.zhang"
	num, err := o.Update(&user)
	fmt.Println("num=",num)
	fmt.Println("err=",err)






}
